﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="ContainerList.aspx.cs" Inherits="TireService.Web.View.ResourceView.ContainerList" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgContainer" alt="" src="~/Images/Medium/cubes_yellow.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblContainerHeader" runat="server" Text="Lagre/Containere"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {
                if (id == 1) {
                    pcAddCargoRooms.Show();
                }

                if (id == 2) {
                    pcCargoRoomTransfer.Show();

                }

            }
            else {
                alert('Ingen handling valgt');
            }
        }

        function AddCargoRooms() {
            
            // Get id
            var id = gvContainer.GetRowKey(gvContainer.GetFocusedRowIndex());

            // Get number of cargo rooms to add
            var addamount = txtAddCargoRooms.GetText();

            var values = id + ',' + addamount;

            // Perform callback to save data
            callBackAddCargoRooms.PerformCallback(values);
        }

        function CargoRoomTransfer() {

        }

        function OnCallbackAddCargoRoomsComplete(s, e) {
            // Hide modal popup
            pcAddCargoRooms.Hide();

            // Refresh gridviews
            gvContainer.PerformCallback();
            gvContainerCargoRoom.PerformCallback();

            alert('Lagerpladser blev tilføjet');
        }

        function CallbackError() {
            alert('Fejl opstod - prøv venligst igen');
        }

    </script>

    <dx:ASPxCallback ID="callBackAddCargoRooms" ClientInstanceName="callBackAddCargoRooms" runat="server" OnCallback="callBackAddCargoRooms_Callback">
        <ClientSideEvents CallbackError="CallbackError" CallbackComplete="OnCallbackAddCargoRoomsComplete" />
    </dx:ASPxCallback>

    <dx:ASPxPopupControl ID="pcAddCargoRooms" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcAddCargoRooms"
        HeaderText="Tilføj lagerpladser" AllowDragging="False" EnableAnimation="False" EnableViewState="False">
        <ContentCollection>
            <dx:PopupControlContentControl runat="server">
                <dx:ASPxPanel ID="Panel1" runat="server" DefaultButton="btOK">
                    <PanelCollection>
                        <dx:PanelContent runat="server">
                            <table width="350px">
                                <tr>
                                    <td>Tilføj lagerpladser</td>
                                    <td>
                                        <dxe:ASPxSpinEdit ID="txtAddCargoRooms" ClientInstanceName="txtAddCargoRooms" runat="server" Height="21px" Number="1" NumberType="Integer" Increment="2">
                                            <SpinButtons ShowIncrementButtons="False" ShowLargeIncrementButtons="True" />
                                        </dxe:ASPxSpinEdit>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <dxe:ASPxButton ID="btnAddContainerCargoRooms" runat="server" ClientIDMode="AutoID" AutoPostBack="False" UseSubmitBehavior="False" Text="Opret">
                                            <ClientSideEvents Click="function(s, e) { AddCargoRooms(); }" />
                                        </dxe:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
    
    <dx:ASPxPopupControl ID="pcCargoRoomTransfer" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcCargoRoomTransfer"
        HeaderText="Flyt hjulsæt til anden lager lokation" AllowDragging="False" EnableAnimation="False" EnableViewState="False">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxPanel ID="ASPxPanel1" runat="server" DefaultButton="btOK">
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent1" runat="server">
                            <table width="450px">
                                <tr>
                                    <td>Til lager</td>
                                    <td>
                                        <dxe:ASPxComboBox ID="ddlMoveToContainer" ClientInstanceName="ddlMoveToContainer" runat="server">
                                        </dxe:ASPxComboBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Til plads</td>
                                    <td>
                                        <dxe:ASPxComboBox ID="ddlMoveToCargoRoom" ClientInstanceName="ddlMoveToCargoRoom" runat="server">
                                        </dxe:ASPxComboBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <dxe:ASPxButton ID="btnCargoRoomTransfer" runat="server" ClientIDMode="AutoID" AutoPostBack="False" UseSubmitBehavior="False" Text="Flyt">
                                            <ClientSideEvents Click="function(s, e) { CargoRoomTransfer(); }" />
                                        </dxe:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>                
                
    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <dxe:ListEditItem Value="1" Text="Tilføj lagerpladser" />
                        <dxe:ListEditItem Value="2" Text="Lagerflyt" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dxe:ASPxButton>
            </td>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dxe:ListEditItem Value="1" Text="Export xls" />
                        <dxe:ListEditItem Value="2" Text="Export csv" />
                        <dxe:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dxe:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Ingen gruppering</asp:ListItem>
                    <asp:ListItem Value="1">Grupper efter By</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />
           
    <dxwgv:ASPxGridView ID="gvContainer" runat="server" ClientInstanceName="gvContainer" 
        KeyFieldName="ContainerId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True" 
        oncustomunboundcolumndata="gvContainer_CustomUnboundColumnData" 
        OnRowInserting="gvContainer_RowInserting"
        OnRowUpdating="gvContainer_RowUpdating">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} lagre/containere)" 
                Text="Side {0} af {1} ({2} lagre/containere)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette lager/container?" GroupPanel="Træk kolonne hertil for at gruppere efter den" HeaderFilterShowAll="Vis alle" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="true" AllowDragDrop="true" AllowFocusedRow="true" />
        <ClientSideEvents FocusedRowChanged="function(s, e) {
            if (typeof(gvContainerCargoRoom) != 'undefined')
                gvContainerCargoRoom.PerformCallback(s.GetFocusedRowIndex());
        }" 
        />
        <Columns>
            <dxwgv:GridViewCommandColumn VisibleIndex="0">
                <EditButton Visible="True" Text="Rediger" />
                <NewButton Visible="True" Text="Opret" />
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvContainer.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerId" VisibleIndex="2" Caption="Container Id">
                <EditFormSettings Visible="False" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="3" Caption="Nummer">
                <EditFormSettings Visible="False" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="SpaceCapacity" VisibleIndex="4" Caption="Kapacitet">
                <EditFormSettings Visible="False" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataTextColumn FieldName="UsedCapacity" VisibleIndex="5" UnboundType="String" Caption="Brugt kapacitet">
                <EditFormSettings Visible="False" />
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="FreeCapacity" VisibleIndex="6" UnboundType="String" Caption="Ledig kapacitet">
                <EditFormSettings Visible="False" />
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataColumn FieldName="Address" VisibleIndex="7" Caption="Adresse">
                <EditFormSettings VisibleIndex="1" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ZipCode" VisibleIndex="8" Caption="Postnr">
                <EditFormSettings VisibleIndex="2" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="City" VisibleIndex="9" Caption="By">
                <EditFormSettings VisibleIndex="3" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataComboBoxColumn Name="CountryDropdown" FieldName="CountryId" Caption="Land" VisibleIndex="10">
                <EditFormSettings VisibleIndex="4" />
            </dxwgv:GridViewDataComboBoxColumn>
            <dxwgv:GridViewDataColumn FieldName="InActive" VisibleIndex="11" Caption="Deaktiveret">
                <EditFormSettings VisibleIndex="5" />
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="NoneMoveableContainer" VisibleIndex="12" Caption="Ikke flytbar">
                <EditFormSettings VisibleIndex="6" />
            </dxwgv:GridViewDataColumn>
        </Columns>
        <SettingsEditing PopupEditFormModal="false" PopupEditFormHorizontalAlign="Center" PopupEditFormAllowResize="false" Mode="PopupEditForm" PopupEditFormWidth="600px" />
        <Templates>
            <EditForm>
                <div style="text-align: left; padding: 2px">
                    <h4>Lager</h4>
                </div>
                <dxwgv:ASPxGridViewTemplateReplacement ID="Editors" ReplacementType="EditFormEditors" runat="server">
                </dxwgv:ASPxGridViewTemplateReplacement>
                <div style="text-align: left; padding: 2px">
                    <% if(gvContainer.IsNewRowEditing) { %>
                        Antal lagerpladser:
                        <dxe:ASPxSpinEdit ID="txtAddContainerCargoRooms" runat="server" Height="21px" Number="1" NumberType="Integer" Increment="2">
                            <SpinButtons ShowIncrementButtons="False" ShowLargeIncrementButtons="True" />
                        </dxe:ASPxSpinEdit>
                    <% } %>
                </div>
                <div style="text-align: right; padding: 2px">
                    <dxwgv:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server">
                    </dxwgv:ASPxGridViewTemplateReplacement>
                    <dxwgv:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server">
                    </dxwgv:ASPxGridViewTemplateReplacement>
                </div>
            </EditForm>
        </Templates>            
    </dxwgv:ASPxGridView>
    <hr />
    <dxwgv:ASPxGridView ID="gvContainerCargoRoom" runat="server" ClientInstanceName="gvContainerCargoRoom" Width="100%" 
        KeyFieldName="ContainerCargoRoomId" AutoGenerateColumns="False" EnableCallBacks="True" 
        oncustomunboundcolumndata="gvContainerCargoRoom_CustomUnboundColumnData" OnCustomCallback="gvContainerCargoRoom_CustomCallback">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} lagerpladser)" 
                Text="Side {0} af {1} ({2} lagerpladser)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne lagerplads?" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="true" AllowFocusedRow="true" AllowDragDrop="true" AllowSelectByRowClick="true" />
        <ClientSideEvents Init="function(s, e) {
	        s.PerformCallback(gvContainer.GetFocusedRowIndex());
        }" />

        <Columns>
            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvContainerCargoRoom.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dxwgv:GridViewCommandColumn>
            <%--<dxwgv:GridViewCommandColumn VisibleIndex="1">
                <CustomButtons>
                    <dxwgv:GridViewCommandColumnCustomButton Text="Kunde" ID="EditCustomer" />
                    <dxwgv:GridViewCommandColumnCustomButton Text="Bil" ID="EditCar" />
                    <dxwgv:GridViewCommandColumnCustomButton Text="Hjulsæt" ID="EditTireSet" />
                    <dxwgv:GridViewCommandColumnCustomButton Text="Abonnement" ID="EditSubscription" />
                </CustomButtons>
            </dxwgv:GridViewCommandColumn>--%>
            <%--<dxwgv:GridViewDataHyperLinkColumn FieldName="TireSetId" VisibleIndex="1" Caption="Log">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/Casehandling/TireSetLogList.aspx?TireSetId={0}" Text="Vis log" >
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>--%>
            <dxwgv:GridViewDataHyperLinkColumn FieldName="ContainerCargoRoomId" VisibleIndex="2" Caption="Labels">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/Reports/View/TireSetLabels.aspx?ContainerCargoRoomId={0}" Target="_blank" Text="Vis labels" >
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerId" Visible="false" VisibleIndex="2" Caption="ContainerId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerCargoRoomId" Visible="false" VisibleIndex="3" Caption="ContainerCargoRoomId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataTextColumn FieldName="CargoRoomNumber" VisibleIndex="4" Caption="Rum nr.">
            </dxwgv:GridViewDataTextColumn>
                                
            <dxwgv:GridViewDataColumn FieldName="CustomerId" Visible="false" VisibleIndex="6" Caption="CustomerId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireSetId" Visible="false" VisibleIndex="7" Caption="TireSetId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CarId" Visible="false" VisibleIndex="8" Caption="CarId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="SubscriptionId" Visible="false" VisibleIndex="9" Caption="SubscriptionId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CustomerSubscriptionId" Visible="false" VisibleIndex="9" Caption="CustomerSubscriptionId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CarBrandDescription" VisibleIndex="9" Caption="Bilmærke">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CarStatusDescription" VisibleIndex="9" Caption="Bilstatus">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireBrandDescription" VisibleIndex="9" Caption="Dækmærke">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireSetStatusDescription" VisibleIndex="9" Caption="Dækstatus">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireDimensions" UnboundType="String" VisibleIndex="9" Caption="Dimensioner">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ManufactureDate" VisibleIndex="9" Caption="Produktionsdato">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="LastTireSetChangeDate" VisibleIndex="9" Caption="Seneste hjulskift">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="NextTireSetChangePlanningDate" VisibleIndex="9" Caption="Næste hjulskift">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Size" VisibleIndex="9" Visible="false" Caption="Size">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Width" VisibleIndex="9" Visible="false" Caption="Width">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Height" VisibleIndex="9" Visible="false" Caption="Height">
            </dxwgv:GridViewDataColumn>
        </Columns>                                            
    </dxwgv:ASPxGridView>

                                
    <dxwgv:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvContainer">
    </dxwgv:ASPxGridViewExporter>
                
</asp:Content>
